<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>isDom</title>
</head>

<body>
    <div id="test">该元素是一个dom元素，打开浏览器控制台查看结果。</div>
    <script>
        const isDom = el => {
            if (typeof HTMLElement === 'object' && !!HTMLElement) {
                return el instanceof HTMLElement || el instanceof HTMLCollection || el instanceof NodeList;
            } else {
                return typeof el === 'object' && !!el && el.nodeType === 1 && typeof el.nodeName === 'string';
            }
        };
        console.log(isDom(document.querySelector('#test')))
    </script>
</body>

</html>